{% extends 'iframe/basePlus.html.twig' %}
{% block search %}
    <div class="layui-fluid">
        <div class="layui-row">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-header">搜索</div>
                    <div class="layui-card-body">
                        <form class="layui-form" onsubmit="return false;">
                            <dry-common role="select" label="模型" name="dry_model" value="" url="/Api/Model/getList"></dry-common>
                            <dry-common role="submit" submit="确定" reset="重置"></dry-common>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
{% endblock %}
{% block cardHeader %}列表{% endblock %}
{% block cardBody %}
    <script type="text/html" id="toolbar">
        <div class="layui-btn-container">
        </div>
    </script>
    <script type="text/html" id="bar">
        <a class="layui-btn layui-btn-xs" lay-event="show">查看</a>
        <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    </script>
    <table class="layui-hide" id="list" lay-filter="list"></table>
    <script>
        function getIndexColumn()
        {
            var list = [
                {
                    title: 'ID',
                    field: 'id',
                    width: ID_WIDTH
                },
                {
                    title: '模型',
                    field: 'dry_model',
                    templet: function(rs){return mergeRequest("tag", "dry_model", rs.dry_model, "/Api/Model/getList", "", 1);}
                },
                {
                    title: '字段ID',
                    field: 'dry_field',
                    hide: true
                },
                {
                    title: '字段名',
                    field: 'dry_database_field'
                },
                {
                    title: '字段',
                    field: 'dry_field',
                    templet: function(rs){return mergeRequest("tag", "dry_field", rs.dry_field, "/Api/Field/getList", "", 1);}
                },
                {
                    title: '表单类型',
                    field: 'dry_form_type',
                    templet: function(rs){return mergeRequest("tag", "dry_form_type", rs.dry_form_type, "/Api/Choice/getListByKey?key=formType", "", 1);}
                },
                {
                    title: '排序',
                    field: 'dry_sort',
                    width: SORT_WIDTH,
                    edit: "text"
                },
                {
                    title: '字段列表排序',
                    field: 'dry_field_list_sort',
                    width: SORT_WIDTH,
                    edit: "text"
                },
                {
                    title: '是否初始隐藏列',
                    field: 'dry_is_init_hide',
                    templet: function(rs){return mergeRequest("tag", "dry_is_init_hide", rs.dry_is_init_hide, "/Api/Choice/getListByKey?key=yesNo", "", 1);}
                },
                {
                    title: '列表即时编辑',
                    field: 'dry_is_list_edit',
                    templet: function(rs){return mergeRequest("tag", "dry_is_list_edit", rs.dry_is_list_edit, "/Api/Choice/getListByKey?key=yesNo", "", 1);}
                },
                {
                    title: '列表点击排序',
                    field: 'dry_is_list_click_sort',
                    templet: function(rs){return mergeRequest("tag", "dry_is_list_click_sort", rs.dry_is_list_click_sort, "/Api/Choice/getListByKey?key=yesNo", "", 1);}
                },
                {
                    title: '字段模板',
                    field: 'dry_field_template',
                    templet: function(rs){return mergeRequest("tag", "dry_field_template", rs.dry_field_template, "/Api/Choice/getListByKey?key=fieldTemplate", "", 1);}
                },
                {
                    title: '字段宽度',
                    field: 'dry_field_width',
                    templet: function(rs){return mergeRequest("tag", "dry_field_width", rs.dry_field_width, "/Api/Choice/getListByKey?key=fieldWidth", "", 1);}
                },
                {
                    title: '添加时间',
                    field: 'dry_add_time',
                    width: ADD_TIME_WIDTH
                },
                {
                    title:'操作',
                    toolbar: '#bar',
                    width: OPERATE_WIDTH
                }
            ];
            return list;
        }

        layui.use(['dry', 'jquery'], function(dry, $){
            var f = {};

            /*即时编辑*/
            f.immediatelyEdit = function(object)
            {
                var parameter = {
                    "id": object.data.id,
                    "field": object.field,
                    "value": object.value
                };
                $.post("/Api/ModelField/editPlus", parameter);
            };

            /*表格渲染结束*/
            f.done = function(response, currentPage, count)
            {
                dry.mergeRequest();
            };

            /*查看按钮*/
            f.show = function(object, id)
            {
                window.location.href = "/Admin/ModelField/show?id=" + id;
            };

            /*编辑按钮*/
            f.edit = function(object, id)
            {
                window.location.href = "/Admin/ModelField/edit?id=" + id;
            };

            /*搜索*/
            f.search = function()
            {
                return {
                    'modelId': $("#dry_model").val()
                };
            };

            function isReady()
            {
                if($("dry-common[name='dry_model']").attr("ok") == "1"){
                    return true;
                }
                return false;
            }

            function list()
            {
                var result = dry.list("/Api/ModelField/index", getIndexColumn(), 100, f);
                config = result.config;
                instance = result.instance;
            }

            var config = null;
            var instance = null;

            dry.runAfter(isReady, list);

            $("button[type='submit']").click(function(){
                config.page = {"curr": 1};
                config.where = f['search']();
                instance.reload(config);
            });
        });
    </script>
{% endblock %}